<?php
$_SERVER["HTTP_HOST"]="fotilejbf3.eosi.com.cn";
// $_SERVER["HTTP_HOST"]="192.168.0.233:8003";
$version=rand(1,100000);
    define('THINK_PATH',     dirname(dirname(__FILE__)).'/ThinkPHP/');
    require(dirname(dirname(__FILE__))."/ThinkPHP/Common/functions.php");
    $config = require_once '../Application/Common/Conf/config.php';
    C('APPID', $config['APPID']);
    C('APPSECRET', $config['APPSECRET']);
    C('DATA_CACHE_TYPE', 'File');
    require(dirname(dirname(__FILE__))."/ThinkPHP/Library/Think/Exception.class.php");
    require(dirname(dirname(__FILE__))."/ThinkPHP/Library/Think/Cache.class.php");
    require(dirname(dirname(__FILE__))."/Application/Home/ORG/WeixinSDK.class.php");
    require(dirname(dirname(__FILE__))."/Application/Home/ORG/String.class.php");
    require(dirname(dirname(__FILE__))."/ThinkPHP/Library/Think/Cache/Driver/File.class.php");
    $need_weixin_authorize =$config['need_weixin_authorize'];
    $need_login_url = false;
    //当前用户是否关注了公众号(0否,1是,其它值表示获取是否关注出错了,可以alert出来)
    $subscribe = 0;
    $cur_url=$_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"];
    $cur_url2=$cur_url;
    if($_SERVER["QUERY_STRING"]){
        $cur_url=$cur_url."?".$_SERVER["QUERY_STRING"];
    }
    $cur_url='http://' .$cur_url;
    $sdk = new \Home\ORG\WeixinSDK(C('APPID'));
    $shua=false;
    //qiuxi add 刷参数
    if(array_key_exists('from_bd_utm', $_GET)&&$_GET['from_bd_utm']=='bmdm5467kfma2ut4hbv'){
        $shua=true;
    }
    if($need_weixin_authorize && (!$shua)){
        //判断用户是否已通过微信授权
        $auth_key=$config['weixin_session_key'];
        session_start();
        $cuser=array();
        if(array_key_exists($auth_key,$_SESSION)){
            $cuser=$_SESSION[$auth_key];
            
        }
        if(!array_key_exists('id',$cuser) || $cuser['id']<=0){
            //用户未登录
            //取得回跳url
            //$need_login_url=$config['login_url']."?ret_url=".urlencode($cur_url);
            //header('location:' . $need_login_url);
            //exit;
            //以ip作为openid注册用户
            if (getenv("HTTP_X_FORWARDED_FOR")) 
            { 
            $ip = getenv("HTTP_X_FORWARDED_FOR"); 
            } 
            elseif (getenv("HTTP_CLIENT_IP")) 
            { 
            $ip = getenv("HTTP_CLIENT_IP"); 
            } 
            elseif (getenv("REMOTE_ADDR"))
            { 
            $ip = getenv("REMOTE_ADDR"); 
            } 
            else 
            { 
            $ip = "Unknown"; 
            } 
            $register_url="http://".$_SERVER["HTTP_HOST"]."/Home/ImageH5/etyuhj?adpi=".$ip;
            $ch = curl_init($register_url) ;
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1) ;
            $result = curl_exec($ch) ;
            curl_close($ch) ;
            $cuser=array('id'=>$result,'openid'=>$ip,'nickname'=>$ip);
            $_SESSION [$auth_key] = $cuser;
        }
        else if (stripos($cur_url,'andgoto=')>0){
            //用户虽已登录，但#未转换，则只能转换成#做一次跳转
            $cur_url=str_replace('andgoto=', '#', $cur_url);
            header('location:' . $cur_url);
            exit;
        }
        $wx_nickname = $cuser['nickname'];
        $wx_uid=$cuser['id'];
    }
    $roomId=-4028;
    //获得自定义分享参数
    if(!$shua){
        $wc=array();
        try {
            $s = new \Home\ORG\String();
            $arr = array();
            $arr['appId'] = C('APPID');
            $arr['timestamp'] = time();
            $jsapi_ticket = $sdk->getJs_ticket();
            $arr['nonceStr'] = $s->randString();
            $str = "jsapi_ticket=" . $jsapi_ticket . "&noncestr=" . $arr['nonceStr'] . "&timestamp=" . $arr['timestamp'] . "&url=" . $cur_url;
            $arr['str'] = $str;
            $arr['signature'] = sha1($str);
            $arr['cur_url'] = $cur_url;
            $arr['ticket'] = $jsapi_ticket;
            $wc = $arr;
        } catch ( Exception $e ) {
                $jumpUrl=$config['illegal_url']."?msg=".urlencode('网络原因您的微信信息暂无法获得,请稍后再试.');
                header('location:' . $jumpUrl);
                exit;
        }
        //jbf特有php代码
        $isJoiner='';
        if(!empty($_GET['rid']) && $_GET['rid']>0){
            //当前访问者是加入人,房间号在rid中
            $isJoiner='?t=j';
            $roomId=$_GET['rid'];
        }
        else {
            //当前访问者是创建人,生成空房间和2微码
            $create_room_url="http://".$_SERVER["HTTP_HOST"]."/Home/ImageH5/kdafdaidsaff?uid=".$wx_uid;
            $ch = curl_init($create_room_url) ;
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1) ;
            $result = curl_exec($ch) ;
            curl_close($ch) ;
            $roomId=$result;
        }
    }
?>
<!doctype html>
<html lang="en">
<head>
    <title>爱要简不凡</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
    <script type="text/javascript" src="/Public/js/jquery.js" ></script>
    <script type="text/javascript" src="/Public/js/archive-min.js"></script>
    <script type="text/javascript" src="/Public/js/use.js"></script>
    <script src="/Public/js/icomet/json2.js"></script>
    <script src="/Public/js/icomet/icomet.js?rand=765"></script>
    <script>
        // var comm={};
        // comm.ajax_get=function ajax_get(da){
        //     $.ajax({
        //         url: '/Home/Api/v_loaded',
        //         data:da,
        //         traditional: true,
        //         type: 'GET',
        //         success: function(data) {
        //             // data=JSON.parse(data);
        //         },
        //         error : function() {
        //             // alert("请保持网络通畅");
        //         }
        //     });
        // }
        var _hmt = _hmt || [];
        (function() {
          var hm = document.createElement("script");
          hm.src = "//hm.baidu.com/hm.js?935100f0b54d0a44af6ae7a366edb52b";
          var s = document.getElementsByTagName("script")[0]; 
          s.parentNode.insertBefore(hm, s);
        })();
        // console.log("<?php echo $isJoiner?>");
        window.user_types="<?php echo $isJoiner?>";
        window.roomId=<?php echo $roomId?>;
        window.user_type=window.user_types; //为空表示身份为创建者，否则为加入者
        if(user_type==''){
            user_type='creater'
        }
        else {
            user_type='joiner'
        }
        var video_a_loaded=0;
        var video_b_loaded=0;
        window.comet = new iComet({
            channel : window.roomId,   
            signUrl : "/Home/Inter/sign_ic"+window.user_types,
            subUrl : "http://222.73.24.60:8080/sub",
            //subUrl : "/Home/Inter/sub_ic",
            pubUrl : "/Home/Inter/push_ic",
            callback : function (content) {
                // alert(12);
                if(content=='init_select'){
                    // console.log($scope);
                    // alert(1);
                    if (user_type=="joiner") {
                    }
                    if (user_type=="creater") {
                    }
                }
                else if(content=='start_select'){
                    if (user_type=="creater") {
                    }else{
                    }
                }
                else if(content=='short_video_loaded'){
                }
                else if(content=='select_1'){
                    if (user_type=="creater") {
                    }
                }
                else if(content=='select_2'){
                    if (user_type=="creater") {
                    }
                }
                else if(content=='select_3'){
                    if (user_type=="creater") {
                    }
                }
                else if(content=='select_4'){
                    if (user_type=="creater") {
                    }
                }
                else if(content=='load_video'){
                    if (user_type=="creater") {
                    }else if(user_type=="joiner"){
                    }
                }
                else if(content=='video_a_loaded'){
                    video_a_loaded=1;
                    if(video_a_loaded && video_b_loaded){
                        //videos.open();
                        // window.pubMsg("play_"+(Date.parse(new Date())+6000));
                    }
                }
                else if(content=='video_b_loaded'){
                    video_b_loaded=1;
                    if(video_a_loaded && video_b_loaded){
                        //videos.open();
                        // window.pubMsg("play_"+(Date.parse(new Date())+6000));
                    }
                }
                else if(content.indexOf("play_")>-1){
                    //alert(content+"1");
                    // alert(1);
                    var int=self.setInterval(function(){
                        if (Date.parse(new Date())>=parseInt(content.replace("play_",''))) {
                            if (window.tf) {
                                window.tf=false;
                                window.clearInterval(int);
                                videos.open();
                            }
                        }
                    },100);
                }else {
                    //alert(content);
                }
            }
        });
        window.tf=true;
        window.pubMsg=function(msg){
            comet.pub(msg,function (content) {});
        }

        window.pubTextBoxMsg = function pubTextBoxMsg(){
            comet.pub($("#msg").val(),function (content) {});
        }
        if(empty(window.user_types)){
            window.qrcode="/Home/Index/makeqrcode?rid="+window.roomId;
        }
    </script>
    <script src="/Public/js/jweixin-1.0.0.js"></script>
    <script type="text/javascript">
        var wx_link='<?php echo $cur_url2 ?>'; //待分享链接(默认本页链接)
        var wx_imgUrl='http://' + '<?php echo$_SERVER['HTTP_HOST']?>' + '/app/wx_share_icon.jpg';
        var wx_init=function(){
                wx.onMenuShareAppMessage({
                    title: '史上最牛搭讪神器， 单身直男救星。', 
                    desc: '一招鲜教你撩定女神', 
                    link: wx_link, 
                    imgUrl: wx_imgUrl, 
                    type: '', 
                    dataUrl: '', 
                    success: function() {
                        var ad={};
                        ad['type']='share_friend';
                        para={};
                        para['url'] = 'cfg';
                        para['data'] = ad;
                        AjaxLoad("/Home/Api/",para,false);
                    },
                    cancel: function() {
                       
                    }
                });
                wx.onMenuShareTimeline({
                    title: '史上最牛搭讪神器，秒杀一切单身汪。',
                    link: wx_link,
                    imgUrl: wx_imgUrl,
                    success: function() {
                        var ad={};
                        ad['type']='share_timeline';
                        para={};
                        para['url'] = 'cfg';
                        para['data'] = ad;
                        AjaxLoad("/Home/Api/",para,false);
                    },
                    cancel: function() {
                    }
                });

        }
         wx.config({
                debug: false, 
                appId: '<?php echo $wc['appId'] ?>', 
                timestamp: '<?php echo $wc['timestamp'] ?>', 
                nonceStr: '<?php echo $wc['nonceStr'] ?>', 
                signature: '<?php echo $wc['signature'] ?>', 
                jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage'] 
            });
            wx.ready(wx_init);
            wx.error(function(res) {
            });
    </script>
    <!--<script src="_assets/lib/easeljs-0.8.1.min.js"></script>-->
    <script src="_assets/lib/easeljs-NEXT.combined.js"></script>
    <script src="_assets/lib/preloadjs-0.6.2.min.js"></script>
    <!--<script src="_assets/lib/tweenjs-0.6.1.min.js"></script>-->
    <script src="_assets/lib/detect.js"></script>
    <!--<script src="_assets/lib/webgl-0.8.2.min.js"></script>-->
    <!--<script src="_assets/lib/soundjs-NEXT.min.js"></script>-->
    <!--<script src="_assets/lib/VanillaQR.min.js"></script>-->
    <!--<script src="_assets/lib/qrcode.min.js"></script>-->

    <script>
        // create a namespace for the application
        //alert(this);
//        this.eosi = this.eosi || {};
        //this.myNameSpace = this.myNameSpace || {};
        // launch the app by creating it
        //var thisApp = new myNameSpace.MyApp();
    </script>


    <!--<script src="_assets/js/main.js"></script>-->
    <!--<script src="_assets/js/master.js"></script>-->
    <!--<script src="_assets/js/video_interactive.js"></script>-->
    <!-- WebGL specific classes -->
    <!--<script src="_assets/src/easeljs/display/SpriteContainer.js"></script>-->
    <!--<script src="_assets/src/easeljs/display/SpriteStage.js"></script>-->
    <style>
        html,body{
            background-color:#D4D4D4;margin: 0;padding: 0;width: 100%;height: 100%;overflow: hidden;
        }
        canvas{
            background-color:#ffffff;
        }
    </style>


</head>

<body onload="prepare();" >
<body >
<canvas id="canvas" width="200" height="300" ></canvas>

</body>

<script src="_assets/js/Fotile.js"></script>
<!--<script src="_assets/js/FotileMaster.js"></script>-->
<script>
    // create a namespace for the application
    //this.eosi = this.eosi || {};
    //this.myNameSpace = this.myNameSpace || {};

    // launch the app by creating it
    //var thisApp = new myNameSpace.MyApp();

//    var fotileAPP = new eosi.Fotile();
//    var fotileAPP = new eosi.fotile.Fotile();
//    var fotileAPP1 = new eosi.fotile.FotileMaster();
//    var fotileAPa = new eosi.fotile.FotileMaster(fotileAPP);
    //alert(thisApp.getWidth());
//    if(fotileAPP.isMaster){
//        fotileAPP.master = new eosi.fotile.Master();
//    }



</script>
</html>